<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Genemoban extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('file');
        $this->load->database();
        $this->load->helper('fuc');
        $this->load->library('topclass');
    }

    public function index() {
        $this->load->view('welcome_message');
    }

   public function genarray($usernick) {//这步生成数组
        $resp = $this->topclass->api_getSellercatsListGetRequest("SellercatsListGetRequest", $usernick, $sessionkey = null);
        objectToArray(&$resp);
        return $resp;
    }

    public function outputmoban() {//根据参数选择，输出模板
        $filename = $_POST["tmp"];
        $widtharray = explode("_", $filename);
        $width = $widtharray[0];
        $data['rrr'] = $this->genarray($_SESSION["usernick"]);
        if (empty($data['rrr'])) {
            echo "<script language=\"javascript\">alert(\"您的店铺还没有分类，请设置淘宝店铺分类：）\")</script>";
            exit;
        }
        $sellarray = $data['rrr']["seller_cats"]["seller_cat"];
        $karray = chagearray($sellarray);
        $data["seller_cat"] = $karray;
        $path = "moban/{$filename}.php";
        $shopid = $_SESSION["shopid"];
        $time = time();
        $insertsql = "INSERT INTO res(shopid,time,tmpath) VALUES (\"{$shopid}\",\"{$time}\",\"{$path}\")";
        $this->db->query($insertsql);
        $this->load->view($path, $data);
    }

    public function displaytmp() {//根据参数选择，输出模板,用于前台模块
        // 读取参数选择数据库
        $sql = "select * from res where shopid={$_GET["shop_id"]}  order by  time  desc limit 1   ";

        $query = $this->db->query($sql);
        $resarray = $query->result_array();
        echo $path = $resarray[0]["tmpath"];
        $data['rrr'] = $this->genarray($_SESSION["usernick"]);
        $sellarray = $data['rrr']["seller_cats"]["seller_cat"];
        $karray = chagearray($sellarray);
        echo "处理后分类数组<br>";
        print_r($karray);
        $sql = "select client.id ,client.shopid ,client.groupid ,client.nickname
,
groups.groupname
 from client,groups where client.shopid= groups.shopid and client.groupid=groups.id and  groups.shopid =\"{$_SESSION["shopid"]}\" ";

        $res = $this->db->query($sql);
        $resarray = $res->result_array();
        echo "<br>未处理客服数组<br>";
        print_r($resarray);


        exit;
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */